package com.jjmmbb.jxSudoku;

import android.os.Bundle;
import android.widget.EditText;
import android.widget.TextView;

import com.adb.dao.GameDataManager;
import com.adb.util.Util;

/**
 * 统计
 * 
 * @author yizhe
 * @date 2012-11-26
 */
public class AnalyseActivity extends BaseActivity {

	TextView titleView;
	EditText infoView;
	GameDataManager gdm;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.analyse);
		titleView = (TextView) findViewById(R.id.analyse_title);
		infoView = (EditText) findViewById(R.id.analyse_info);

		titleView.requestFocus();

		ini();
		setNightMode();
	}

	public void ini() {
		gdm = new GameDataManager();

		// 简单
		String sql_avg_easy = "select avg(time_best) as num from gamedata where grade = 1 and state = 1";
		int time_avg_easy = gdm.getNumAsSQL(this, sql_avg_easy);

		String sql_finish_easy = "select count(id) as num from gamedata where grade = 1 and state = 1";
		int sum_easy_finish = gdm.getNumAsSQL(this, sql_finish_easy);

		String sql_all_easy = "select count(id) as num from gamedata where grade = 1";
		int sum_easy_all = gdm.getNumAsSQL(this, sql_all_easy);

		// 专家
		String sql_avg_general = "select avg(time_best) as num from gamedata where grade = 2 and state = 1";
		int time_avg_general = gdm.getNumAsSQL(this, sql_avg_general);

		String sql_finish_general = "select count(id) as num from gamedata where grade = 2 and state = 1";
		int sum_general = gdm.getNumAsSQL(this, sql_finish_general);

		String sql_all_general = "select count(id) as num from gamedata where grade = 2";
		int sum_general_all = gdm.getNumAsSQL(this, sql_all_general);

		// 大师
		String sql_avg_hard = "select avg(time_best) as num from gamedata where grade = 3 and state = 1";
		int time_avg_hard = gdm.getNumAsSQL(this, sql_avg_hard);

		String sql_finish_hard = "select count(id) as num from gamedata where grade = 3 and state = 1";
		int sum_hard = gdm.getNumAsSQL(this, sql_finish_hard);

		String sql_all_hard = "select count(id) as num from gamedata where grade = 3";
		int sum_hard_all = gdm.getNumAsSQL(this, sql_all_hard);

		// toast(time_avg_easy + "  " + sum_easy + "");
		//
		// toast(time_avg_general + "  " + sum_general);
		//
		// toast(time_avg_hard + "   " + sum_hard);

		StringBuffer bs = new StringBuffer();
		bs.append("\n" + getStr(R.string.main_easy) + ":\n     ");
		bs.append(getStr(R.string.analyse_avg_time));
		bs.append(Util.secondFormat(time_avg_easy) + "  ");
		bs.append(getStr(R.string.analyse_now_sum));
		bs.append(sum_easy_finish);
		bs.append("/");
		bs.append(sum_easy_all);

		bs.append("\n" + getStr(R.string.main_expert) + ":\n     ");
		bs.append(getStr(R.string.analyse_avg_time));
		bs.append(Util.secondFormat(time_avg_general) + "  ");
		bs.append(getStr(R.string.analyse_now_sum));
		bs.append(sum_general);
		bs.append("/");
		bs.append(sum_general_all);

		bs.append("\n" + getStr(R.string.main_master) + ":\n     ");
		bs.append(getStr(R.string.analyse_avg_time));
		bs.append(Util.secondFormat(time_avg_hard) + "  ");
		bs.append(getStr(R.string.analyse_now_sum));
		bs.append(sum_hard);
		bs.append("/");
		bs.append(sum_hard_all);

		infoView.setText(bs.toString());

	}

}